package com.parkinglot.biz;

import cn.hutool.core.collection.CollectionUtil;
import com.parkinglot.dao.OrderDao;
import com.parkinglot.vo.CarParkStatisticsVo;
import com.parkinglot.vo.SelectCarParkByTimeVo;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Component
public class CarParkActiveStatistics extends Statistics {
    @Resource
    OrderDao orderDao;


    @Override
    protected void statistics(StatisticsContext context) {
        List<SelectCarParkByTimeVo> timeVos = orderDao.selectCarParkByTime(context);
        if (CollectionUtil.isEmpty(timeVos)) return;

        context.setResult(new CarParkStatisticsVo(
                        timeVos.stream().map(SelectCarParkByTimeVo::getCount).collect(Collectors.toList()),
                        timeVos.stream().map(SelectCarParkByTimeVo::getName).collect(Collectors.toList())));
    }


}
